<template>
  <div
    @wheel.stop="handleScroll"
    class="jy-style-height Cultural-box"
    :style="{
      'background-image': `url(${publicUrls + 'free/style1/publicStyle1Bg.png' + '?imageView2/3/format/webp'})`,
    }"
  >
    <div class="Cultural-heard">
      <i class="freeIcon" @click="blankHome">&#xe642;</i>
      <span class="Cultural-heard-title">文创商品</span>
      <i class="freeIcon">&#xe642;</i>
      <!-- <div class="percentage-text">
        <span v-if="list.length > 4">{{ percentage }}%</span>
      </div> -->
    </div>
    <ScrollBoxCom
      color="rgba(50, 43, 37, 1)"
      :scrollSrc="publicUrls + 'free/style1/pen.png'"
      v-if="Scrollwidth"
      :byid="9867"
      :width="getScrollWidth"
    >
      <template #solidBorderExcon>
        <div
          class="right-scroll"
          ref="scrollBox"
          :style="list?.length <= 4 && { justifyContent: 'center', paddingLeft: '0px' }"
        >
          <div class="is-null" v-if="list.length === 0 && !loading"><span>暂无文创商品</span></div>
          <!-- <div class="is-null" v-if="list.length === 0 && !loading"><span>暂无文创商品</span></div> -->
          <div class="item-parent" v-for="(item, index) in list" :key="item.id">
            <div class="item" :class="{ 'item-1': index === 0, 'item-max': index === list.length - 1 }">
              <div class="item-img-box" @click="pathLink(item.url)">
                <img :src="publicUrls + 'free/style1/CulturalStyle1Item.png'" class="item-img-99" alt="" />
                <img
                  class="item-img t-image t-image--fit-cover t-image--position-center"
                  v-if="!item.coverUrl"
                  src="http://101.34.143.36:8890/api/image/387939155165253"
                  alt=""
                />
                <img
                  class="item-img t-image t-image--fit-cover t-image--position-center"
                  v-else
                  :src="$filters.getLinkUrl(item.coverUrl + '?imageView2/1/w/270/h/270/format/webp')"
                  alt=""
                />
              </div>
              <p class="item-name">{{ item.name }}</p>
              <div class="item-btm">
                <span class="item-title2" v-if="item.price">{{ item.price }}</span>
                <span class="item-title3" v-if="item.price">参考价</span>
                <span class="item-title2 item-title4" v-else>暂无价格</span>
              </div>
            </div>
          </div>
        </div>
      </template>
      <template #solidBorderExbar>
        <div class="solidBorder-child"></div>
      </template>
    </ScrollBoxCom>
  </div>
</template> 

<script lang="ts">
export default defineComponent({
  name: 'style1',
});
</script>

<script setup lang="ts">
// @ts-nocheck
import { publicUrls } from '@/utils/minxin';
import { goodsList } from '@/api/goods/goods';
import RightMenu from '../components/rightMenu.vue';
import Logo from '../components/logo.vue';
import FooterHome from '../components/footerHome.vue';
import PublicTitle from '../components/PublicTitle.vue';
import { useRouter, useRoute } from 'vue-router';
import ScrollBoxCom from '../scrollBox.vue';
import { ref, watch, reactive, nextTick, defineComponent } from 'vue';
import { copyrightSave, copyrightInfo } from '@/api/templates/templates';
import { useProjectStore, commonDataStore } from '@/store';
import { storeToRefs } from 'pinia';
import { computed } from 'vue';

const parmas = reactive({
  value: '',
  pageNo: 1,
  pageSize: 100,
});
const topShow = ref(false);
const scrollBox = ref(null);
const percentage = ref(0);
const list = ref([]);
const total = ref(0);
const loading = ref(false);
const store = useProjectStore();
const Scrollwidth = ref();
const router = useRouter();
const route = useRoute();
const Description = ref('');
const init = async () => {
  try {
    if (loading.value) {
      return;
    }
    loading.value = true;
    let res = await goodsList(localStorage.getItem('projectId'), parmas);
    total.value = res.data.total;
    list.value = list.value.concat(res.data.data);
    // list.value = [];
    loading.value = false;
  } catch {
    loading.value = false;
  }
};
init();

let viewportwidth = window.innerWidth;
Scrollwidth.value = (viewportwidth / 900) * 569;

const getScrollWidth = computed(() => {
  let widths = (window.innerWidth / 900) * 569;
  return widths;
});

const handleScroll = (event) => {
  event.preventDefault(); // 阻止默认滚动行为
  const { deltaY } = event;

  // 获取滚动内容的 DOM 元素
  const contentEl = scrollBox.value;

  // 将滚动盒子向前滚动
  contentEl.scrollLeft += deltaY;
  if (contentEl.scrollWidth > contentEl.clientWidth) {
    if (
      contentEl.scrollWidth < contentEl.scrollLeft + contentEl.clientWidth + 100 &&
      !loading.value &&
      list.value.length < total.value
    ) {
      parmas.pageNo = parmas.pageNo + 1;
      init();
    }
    nextTick(() => {
      const { scrollLeft, clientWidth, scrollWidth } = scrollBox.value;
      if (scrollLeft > 100) {
        topShow.value = true;
      }
      if (scrollLeft < 100) {
        topShow.value = false;
      }
      const newScrollPercentage = Math.floor((scrollLeft / (scrollWidth - clientWidth)) * 100);
      percentage.value = newScrollPercentage == 99 ? 100 : newScrollPercentage;
    });
  }
};
const emitTop = () => {
  //点击回到列表最左侧
  scrollBox.value.scrollLeft = 0;
  percentage.value = 0;
  topShow.value = false;
};
const pathLink = (url?: string) => {
  if (!url) {
    return;
  }
  window.open(url, '_blank');
};
const blankHome = () => {
  router.push({ name: route.meta.loopType ? 'exhibitionHome' : 'templateedit' });
};
// import { publicUrls } from '@/utils/minxin';
// import { commonDataStore } from '@/store';
// const commonStore = commonDataStore();
// import { useRouter, useRoute } from 'vue-router';
// const router = useRouter();
// const route = useRoute();
// const blankHome=()=>{
//     router.push({name:route.meta.loopType?'exhibitionHome' : 'templateedit'})
// }
</script>

<style scoped lang="less">
.Cultural-box {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 120px 0;
  padding-bottom: 0px;
  background-size: 100% 100%;
}
.Cultural-heard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 80px;
  margin-bottom: 54px;
  .freeIcon {
    cursor: pointer;
    font-size: 40px;
    line-height: 40px;
    color: rgba(50, 43, 37, 1);
    &:last-child {
      opacity: 0;
      cursor: default;
    }
  }
  .Cultural-heard-title {
    font-family: SourceHanSerifCN-Bold;
    font-size: 36px;
    line-height: 56px;
    text-align: center;
    color: rgba(50, 43, 37, 1);
  }
  .percentage-text {
    display: flex;
    justify-content: flex-end;
    font-family: SourceHanSerifCN-Bold;
    font-size: 24px;
    line-height: 56px;
    text-align: center;
    color: rgba(50, 43, 37, 1);
    width: 120px;
  }
}
.right-scroll {
  display: flex;
  width: 100%;
  height: 424px;
  padding-left: 80px;
}
.right-scroll::-webkit-scrollbar {
  display: none;
}
.item-parent {
  margin-right: 20px;
}
.item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 346px;
  height: 424px;
}

.item-img-box {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 346px;
  height: 330px;
}
.item-img-99 {
  position: absolute;
  top: 0px;
  left: 0px;
  width: 346px;
  height: 330px;
}
.item-img {
  position: relative;
  z-index: 30;
  width: 316px;
  height: 314px;
}
.item-name {
  width: 100%;
  font-family: Microsoft YaHei;
  font-size: 18px;
  line-height: 36px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 8px;
  margin-bottom: 2px;
  color: rgba(50, 43, 37, 1);
  text-indent: 0rem !important;
}
.item-btm {
  width: 100%;
  display: flex;
  align-items: baseline;
}
.item-title2 {
  margin-right: 2px;
  color: #322b25;
  font-family: 'SourceHanSerifCN';
  font-size: 22px;
  line-height: 34px;
}

.item-title3 {
  color: #322b25;
  font-family: 'SourceHanSerifCN';
  font-size: 12px;
  line-height: 18px;
  opacity: 0.8;
}
.item-title4 {
  width: 100%;
  color: #322b25;
  text-align: center;
  font-family: 'SourceHanSerifCN';
  font-size: 16px;
  font-weight: 500;
  line-height: 34px;
  text-align: start;
}
.solidBorder-child {
  width: 100%;
  height: 4px;
  border-radius: 1.055px;
  opacity: 0.1;
  background: #6c5c4f;
  box-sizing: border-box;
  border-left: 2px solid rgba(81, 81, 81, 1);
  border-right: 2px solid rgba(81, 81, 81, 1);
}
.is-null {
  margin: 0 auto;
  // margin-left: -100px;
  margin-top: 200px;
  text-align: center;
  span {
    font-size: 20px;
    line-height: 32px;
    color: rgba(50, 43, 37, 1);
  }
}
.item-max {
  margin-right: 80px;
}
</style>